﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PACKETPARSERMAX20.CORE
{
    public static class FlagsExtensions
    {
        public static string DumpFlags(this SpellCastFlags pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                SpellCastFlags tTemp = (SpellCastFlags)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (SpellCastFlags)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (SpellCastFlags)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static string DumpFlags(this OBJECT_UPDATE_FLAGS pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                OBJECT_UPDATE_FLAGS tTemp = (OBJECT_UPDATE_FLAGS)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (OBJECT_UPDATE_FLAGS)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (OBJECT_UPDATE_FLAGS)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static string DumpFlags(this SpellMissInfo pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                SpellMissInfo tTemp = (SpellMissInfo)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (SpellMissInfo)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (SpellMissInfo)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static string DumpFlags(this AURA_FLAGS pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                AURA_FLAGS tTemp = (AURA_FLAGS)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (AURA_FLAGS)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (AURA_FLAGS)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static string DumpFlags(this SplineFlags pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                SplineFlags tTemp = (SplineFlags)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (SplineFlags)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (SplineFlags)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static string DumpFlags(this SpellEffects pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                SpellEffects tTemp = (SpellEffects)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (SpellEffects)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (SpellEffects)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static string DumpFlags(this MonsterMovementFlags pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                MonsterMovementFlags tTemp = (MonsterMovementFlags)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (MonsterMovementFlags)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (MonsterMovementFlags)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static string DumpFlags(this SpellCastTargetFlags pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                SpellCastTargetFlags tTemp = (SpellCastTargetFlags)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (SpellCastTargetFlags)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (SpellCastTargetFlags)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static string DumpFlags(this  HitInfo pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                HitInfo tTemp = (HitInfo)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (HitInfo)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (HitInfo)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static string DumpFlags(this  UINT_FLAGS pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                UINT_FLAGS tTemp = (UINT_FLAGS)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (UINT_FLAGS)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (UINT_FLAGS)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static string DumpFlags(this  MovementFlags pflags)
        {
            uint i = 0;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("\t-------------------------------");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = ((uint)pflags & i) > 0;
                MovementFlags tTemp = (MovementFlags)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = (MovementFlags)((uint)pflags & ~i);
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = (MovementFlags)((uint)pflags & ~i);
                        //sb.AppendLine(tTemp.ToString() + " " + tbool.ToString());
                        sb.AppendLine(string.Format("\t{0} 0x{1} = {2}", tTemp.ToString(), ((uint)tTemp).ToString("X4"), tbool));

                    }

                }
            }
            if (pflags > 0) { sb.AppendLine("\tLeft Overs: " + pflags.ToString()); }
            sb.AppendLine("\t-------------------------------");


            return sb.ToString();
        }
        public static void DebugMovementFlags(this uint pflags)
        {
            uint i = 0;
            System.Diagnostics.Debug.WriteLine("********************************");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = (pflags & i) > 0;
                MovementFlags tTemp = (MovementFlags)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        System.Diagnostics.Debug.WriteLine(tTemp.ToString() + " " + tbool.ToString());
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        System.Diagnostics.Debug.WriteLine(tTemp.ToString() + " " + tbool.ToString());
                    }

                }
            }
            if (pflags > 0) { System.Diagnostics.Debug.WriteLine("Left Overs: " + pflags.ToString()); }
            System.Diagnostics.Debug.WriteLine("********************************");
        }
        public static string DebugHitInfoFlags(this uint pflags)
        {
            uint i = 0;
            string tstr = "********************************";
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = (pflags & i) > 0;
                HitInfo tTemp = (HitInfo)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        tstr += "\r\n" + tTemp.ToString() + " " + tbool.ToString();
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        tstr += "\r\n" + tTemp.ToString() + " " + tbool.ToString();
                    }

                }
            }
            if (pflags > 0) { tstr += "\r\n" + "Left Overs: " + pflags.ToString(); }
            tstr += "\r\n" + "********************************";
            return tstr;
        }

        public static string DebugAURAFLAGS(this uint pflags)
        {
            uint i = 0;
            string tstr = "********************************";
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = (pflags & i) > 0;
                AURA_FLAGS tTemp = (AURA_FLAGS)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        tstr += "\r\n" + tTemp.ToString() + " " + tbool.ToString();
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        tstr += "\r\n" + tTemp.ToString() + " " + tbool.ToString();
                    }

                }
            }
            if (pflags > 0) { tstr += "\r\n" + "Left Overs: " + pflags.ToString(); }
            tstr += "\r\n" + "********************************";
            return tstr;
        }

        public static void DebugFlags(this uint pflags)
        {
            uint i = 0;
            System.Diagnostics.Debug.WriteLine("********************************");
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = (pflags & i) > 0;
                UINT_FLAGS tTemp = (UINT_FLAGS)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        System.Diagnostics.Debug.WriteLine(tTemp.ToString() + " " + tbool.ToString());
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        System.Diagnostics.Debug.WriteLine(tTemp.ToString() + " " + tbool.ToString());
                    }

                }
            }
            if (pflags > 0) { System.Diagnostics.Debug.WriteLine("Left Overs: " + pflags.ToString()); }
            System.Diagnostics.Debug.WriteLine("********************************");
        }

        public static void DebugObjectUpdateFlags(this uint pflags)
        {
            uint i = 0;
            System.Diagnostics.Debug.WriteLine("********************************");
            while (i <= 0x40)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = (pflags & i) > 0;
                OBJECT_UPDATE_FLAGS tTemp = (OBJECT_UPDATE_FLAGS)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        System.Diagnostics.Debug.WriteLine(tTemp.ToString() + " " + tbool.ToString());
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        System.Diagnostics.Debug.WriteLine(tTemp.ToString() + " " + tbool.ToString());
                    }

                }
            }
            if (pflags > 0) { System.Diagnostics.Debug.WriteLine("Left Overs: " + pflags.ToString()); }
            System.Diagnostics.Debug.WriteLine("********************************");
        }

        public static string DebugUnitFlags(this uint pflags)
        {
            uint i = 0;
            string tstr = "********************************";
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = (pflags & i) > 0;
                UnitFlags tTemp = (UnitFlags)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        tstr += "\r\n" + tTemp.ToString() + " " + tbool.ToString();
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        tstr += "\r\n" + tTemp.ToString() + " " + tbool.ToString();
                    }

                }
            }
            if (pflags > 0) { tstr += "\r\n" + "Left Overs: " + pflags.ToString(); }
            tstr += "\r\n" + "********************************";
            return tstr;
        }

        public static string DebugUnitFlags2(this uint pflags)
        {
            uint i = 0;
            string tstr = "********************************";
            while (i <= 0x40000000)
            {
                if (i < 2) { i++; } else { i *= 2; }
                bool tbool = (pflags & i) > 0;
                UnitFlags2 tTemp = (UnitFlags2)i;
                if (!(System.Text.RegularExpressions.Regex.IsMatch(tTemp.ToString(), "[0-9]+")))
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        tstr += "\r\n" + tTemp.ToString() + " " + tbool.ToString();
                    }
                }
                else
                {
                    if (tbool)
                    {
                        pflags = pflags & ~i;
                        tstr += "\r\n" + tTemp.ToString() + " " + tbool.ToString();
                    }

                }
            }
            if (pflags > 0) { tstr += "\r\n" + "Left Overs: " + pflags.ToString(); }
            tstr += "\r\n" + "********************************";
            return tstr;
        }
    }
}
